﻿using McMaster.Extensions.CommandLineUtils;
using System;
using System.Diagnostics;

namespace Batman.CommandLine.Utils
{
    public class ProcessUtil
    {
        public static void StarBatFile(string file, CommandLineApplication app)
        {
            Process proc = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = AppDomain.CurrentDomain.BaseDirectory + file,
                    UseShellExecute = false,
                    CreateNoWindow = true,
                    RedirectStandardInput = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError = true
                }
            };
            proc.Start();
            proc.WaitForExit();

            var stderr_str = proc.StandardError.ReadToEnd();
            app.Out.WriteLine(stderr_str);
            var stdout_str = proc.StandardOutput.ReadToEnd();
            app.Out.WriteLine(stdout_str);
        }
    }
}
